class Solution:
    def countNodes(self, root: TreeNode) -> int:
        count=0
        def traverse(node):
            nonlocal count
            count+=1
            if node.left:
                traverse(node.left)
            if node.right:
                traverse(node.right)
        if not root:
            return 0
        traverse(root)
        return count

#位运算加二分查找